{% extends "base.html" %} {% block title %}{{ post.title }} - 运动健康管理系统{%
endblock %} {% block content %}
<div class="container py-5">
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item">
        <a href="{{ url_for('community') }}">社区交流</a>
      </li>
      <li class="breadcrumb-item active" aria-current="page">帖子详情</li>
    </ol>
  </nav>


  <div class="card shadow mb-4">
    <div class="card-body p-4">
      <h2 class="card-title">{{ post.title }}</h2>
      <div class="d-flex justify-content-between align-items-center mb-3">
        <div>
          <span class="text-muted">作者: {{ post.user.username }}</span>
        </div>
        <div>
          <small class="text-muted"
            >发布于: {{ post.created_at.strftime('%Y-%m-%d %H:%M') }}</small
          >
        </div>
      </div>

      <div class="post-content mb-4">{{ post.content|safe }}</div>

      <div class="d-flex justify-content-between align-items-center">
        <div>
          <span class="me-3"
            ><i class="bi bi-eye"></i> {{ post.view_count }}</span
          >
          <span><i class="bi bi-chat"></i> {{ post.comments|length }}</span>
        </div>
        <div>
          {% if current_user.is_authenticated %}
          <form
            method="POST"
            action="{{ url_for('like_post', post_id=post.id) }}"
            class="d-inline">
            <button type="submit" class="btn btn-outline-danger">
              <i class="bi bi-heart"></i> 点赞 ({{ post.like_count }})
            </button>
          </form>
          {% else %}
          <span class="text-muted"
            ><i class="bi bi-heart"></i> {{ post.like_count }}</span
          >
          {% endif %}
        </div>
      </div>
    </div>
  </div>

  <!-- 评论区 -->
  <div class="card shadow mb-4">
    <div class="card-header bg-light">
      <h3 class="mb-0">评论 ({{ post.comments|length }})</h3>
    </div>
    <div class="card-body">
      {% if post.comments %}
      <div class="list-group list-group-flush">
        {% for comment in post.comments %}
        <div class="list-group-item">
          <div class="d-flex justify-content-between align-items-center">
            <h6 class="mb-0">{{ comment.user.username }}</h6>
            <small class="text-muted"
              >{{ comment.created_at.strftime('%Y-%m-%d %H:%M') }}</small
            >
          </div>
          <p class="mb-0 mt-2">{{ comment.content }}</p>
        </div>
        {% endfor %}
      </div>
      {% else %}
      <p class="text-muted">暂无评论，成为第一个评论的人吧！</p>
      {% endif %}
    </div>
  </div>

  <!-- 发表评论 -->
  {% if current_user.is_authenticated %}
  <div class="card shadow">
    <div class="card-header bg-light">
      <h3 class="mb-0">发表评论</h3>
    </div>
    <div class="card-body">
      <form
        method="POST"
        action="{{ url_for('add_comment', post_id=post.id) }}">
        <div class="mb-3">
          <label for="content" class="form-label">评论内容</label>
          <textarea
            class="form-control"
            id="content"
            name="content"
            rows="3"
            required></textarea>
        </div>
        <button type="submit" class="btn btn-primary">提交评论</button>
      </form>
    </div>
  </div>
  {% else %}
  <div class="alert alert-info">
    <p class="mb-0">
      请 <a href="{{ url_for('login', next=request.path) }}">登录</a> 后发表评论
    </p>
  </div>
  {% endif %}
</div>
{% endblock %}
